package com.projet.instamiam;

import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.MediaStore;
import android.app.Activity;
import android.app.ListActivity;
import android.content.ActivityNotFoundException;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.CursorWrapper;
import android.graphics.Bitmap;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class AnnotationActivity extends Activity implements OnClickListener {
	private Long id;
	private Cursor c;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_annotation);
		
		Intent intent = this.getIntent();
		id = intent.getLongExtra("com.projet.instamiam.message", (long)-1);
		System.out.println(id);
		//Toast.makeText(this,String.valueOf(message), Toast.LENGTH_SHORT).show();
		
		ImageView iv = (ImageView) findViewById(R.id.imageView1);
		Bitmap b;
        b=MediaStore.Images.Thumbnails.getThumbnail(this.getContentResolver(), id, MediaStore.Images.Thumbnails.MINI_KIND, null);
		iv.setImageBitmap(b);
	
		
		((Button) this.findViewById(R.id.buttonLayout)).setOnClickListener(this);
		
		
		/* TEST */ 
		
		/*c = getContentResolver().query(
				Uri.withAppendedPath(InstaMiamContract.Annotation.CONTENT_URI, "picture/"+id),
				new String[] { InstaMiamContract.Annotation.PEOPLE_ID },
				InstaMiamContract.Annotation.PICTURE_ID+"=?",
				new String[] { id+"" }, null);
*/
				
		c = managedQuery(ContactsContract.Contacts.CONTENT_URI, null, null,
				null, null);

		int[] to = new int[] { R.id.textViewLayout };

		SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
				R.layout.simple_list_button, c,
				new String[] { ContactsContract.Contacts.DISPLAY_NAME }, to);

		ListView lv = (ListView) findViewById(R.id.listView1);
		lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
		lv.setAdapter(adapter);
		
            	

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.annotation, menu);
		return true;
	}

	@Override
	public void onClick(View v) {

		Intent intent = null;
		switch (v.getId()) {
		case R.id.buttonLayout:
			// Toast.makeText(MainActivity.this,
			// CompleteAction,Toast.LENGTH_SHORT).show();
			intent = new Intent(AnnotationActivity.this, ContactListActivity.class);
			intent.putExtra("com.projet.instamiam.message", id);

			try {
				AnnotationActivity.this.startActivity(intent);
			} catch (ActivityNotFoundException e) {
				Toast.makeText(AnnotationActivity.this, "Erreur",
						Toast.LENGTH_SHORT).show();
			}

			break;
		}
	}

}
